package com.qf.leadnewscommon.content_security;

import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.qf.leadnewscommon.content_security.adapters.ProfileDefaultAcsClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 内容安全检测的自动配置类
 */
@Configuration
@EnableConfigurationProperties(CSProperties.class)
@ConditionalOnProperty(name = "cs.enable",havingValue = "true")
public class CSAutoConfiguration {
    @Autowired
    private CSProperties csProperties;

    @Bean
    public IAcsClient iAcsClient(){
        IClientProfile profile = DefaultProfile
                .getProfile("cn-shanghai", csProperties.getAccessKeyId(), csProperties.getAccessKeySecret());
        DefaultProfile
                .addEndpoint("cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
        IAcsClient client = new ProfileDefaultAcsClient(profile);

        return client;
    }

    @Bean
    public ScanOperator scanOperator(IAcsClient iAcsClient){
        return new ScanOperator(iAcsClient,csProperties);
    }

}
